﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using System.Data;
using ZYO.资源;

namespace ZYO
{
    /// <summary>
    /// ZYDateTime.
    /// </summary>
    public class ZYDateTime
    {

        private String pName;
        public String Name
        {
            get { return this.pName; }
        }

        private class甲子 JZYear;
        public class甲子 年干支
        {
            get { return this.JZYear; }
        }
        private class甲子 JZMonth;
        public class甲子 月干支
        {
            get { return this.JZMonth; }
        }
        private class甲子 JZDay;
        public class甲子 日干支
        {
            get { return this.JZDay; }
        }
        private class甲子 JZHour;
        public class甲子 时干支
        {
            get { return this.JZHour; }
        }

        private DateTime DTCurrent;//当前的时间
        public DateTime 当前时间
        {
            get { return this.DTCurrent; }
        }
        private class节气 jqThisMonth;	//本月的节气
        public class节气 本月节气
        {
            get { return this.jqThisMonth; }
        }
        private class节气 jqCurrrent;
        public class节气 所处节气
        {
            get { return this.jqCurrrent; }

        }

        private int ju;
        public int 所处之局
        {
            get { return this.ju; }
        }

        public class地支[] 旬空;

        public ZYDateTime()
        {
            DTCurrent = DateTime.Now;
            ini();
        }

        public ZYDateTime(DateTime dtTime)
        {
            DTCurrent = dtTime;
            ini();
        }

        public ZYDateTime(int year, int month, int day, int hour)
        {
            DTCurrent = new DateTime(year, month, day, hour, 0, 1);
            ini();
        }

        private void ini()
        {
            jqThisMonth = new class节气(DTCurrent);

            int theYear;
            int theMonth;
            int theDay;
            int theHour;

            //计算 年 甲子===============================================================
            theYear = DTCurrent.Year;
            DateTime dtFeb = new DateTime(theYear, 2, 8);//For 2月份的节气
            class节气 jq = new class节气(dtFeb); //检查2月份的节气，以判断年份

            if (jq.节气日期 > DTCurrent)
                theYear = theYear - 1;

            theYear = theYear - 1983;

            while (theYear < 0)
            {
                theYear = theYear + 60;
            }

            JZYear = new class甲子(theYear % 60);

            //计算 月 甲子===============================================================

            theMonth = DTCurrent.Month;

            if (jqThisMonth.节气日期 > DTCurrent)
            {
                theMonth = theMonth - 1;
            }

            int dz;
            dz = (theMonth - 1 + 2) % 12;

            int yinli; //阴历的月份数

            //将地支 转换为 阴历的月份数======
            if (dz <= 2)  //亥子丑月
                yinli = dz + 10;
            else
                yinli = dz - 2;

            //一月份（寅）的天干为年的天干 *2+1  +月份偏移量 /* - 1（寅）1月*/
            int tg;
            tg = 2 * JZYear.天干.ID + 1 + (yinli - 1); //*月份数-偏移量*/

            JZMonth = new class甲子(tg % 10, dz % 12);

            //计算 日 甲子===============================================================

            DateTime DT1997 = new DateTime(1997, 3, 22, 0, 0, 0, 0);// 1997,3,23是甲子日
            System.TimeSpan Duration = DTCurrent.Date - DT1997;

            int Dur = Duration.Days;
            while (Dur < 0)
                Dur = Dur + 60000;

            theDay = Dur % 60;

            JZDay = new class甲子(theDay);

            //计算 时 甲子===============================================================

            theHour = DTCurrent.Hour;

            int dzHour = (theHour + 1) / 2 + 1;
            int tgHour = 2 * JZDay.天干.ID - 1 + dzHour - 1;

            JZHour = new class甲子(tgHour, dzHour);

            // Assign the Name field
            pName = JZYear.Name + "年" + JZMonth.Name + "月" + JZDay.Name + "日"
                + JZHour.Name + "时 ";// +JZDay.DZEmpty[0].Name + JZDay.DZEmpty[1].Name + "旬空";

            旬空 = new class地支[2];
            旬空 = JZDay.DZ旬空;

            // 计算当前所处的节气
            // 相邻的节气 =========================================

            //class节气 last下旬节气 = this.jqThisMonth--;
            //class节气 this上旬节气 = this.jqThisMonth;
            //class节气 this下旬节气 = this.jqThisMonth++;
            //class节气 next上旬节气 = this下旬节气++;

            class节气 jqTemp;
            for (int i = -1; i <= 2; i++) 
            {
                jqTemp = this.jqThisMonth + i;
                if (isFutouMatched(JZDay, jqTemp))
                {
                    this.jqCurrrent = jqTemp;
                    break;
                }
            }


            this.ju = this.jqCurrrent.局[(int)(this.JZDay.所属之元)];
        }

        private bool isFutouMatched(class甲子 jz, class节气 jq)
        {
            bool isMatched = (jz.上元符头.Equals(jq.节气上元符头));

            if (jq.is闰)
            {
                if (jz.上元符头.Equals(jq.闰节气上元符头))
                {
                    isMatched = true;
                }
            }

            return isMatched;
        }

    }

    /// <summary>
    /// 天干
    /// </summary>
 
    public class class天干 : ZYObject
    {

        internal override void preLoad()
        {
            this.Sum = 10;
            this.EnumType = typeof(e天干);
            base.preLoad();
        }

        internal override void postLoad()
        {
            base.postLoad();
            //
        }


        public class天干():base()
        {
        }

        public class天干(String strName)
            :base(strName)
        {
            this.五行属性 = (e五行)Enum.Parse(typeof(e五行), 资源.天干.五行.Split(';')[this.ID],true);
        }

        public class天干(int iID)
            : base(iID)
        {
            this.五行属性 = (e五行)Enum.Parse(typeof(e五行), 资源.天干.五行.Split(';')[this.ID], true);
        }
        public class天干(e天干 eTG)
            : this((int)eTG)
        {
        }

        /// <summary>
        /// 以本天干为中心计算参数的角色，如：正官，偏财 等等
        /// </summary>
        /// <param name="TG"> 需算角色的天干</param>
        /// <returns></returns>
        public ZYOEnum.e八字六神 Role(class天干 inTG)
        {
            ZYOEnum.e八字六神 ret = ZYOEnum.e八字六神.偏财; //default value
            if (null == inTG)
            {
                throw new Exception("Null value of input 天干 in Role()");
            }

            switch (ZYOEnum.Compair(this.五行属性, inTG.五行属性))
            {
                case ZYOEnum.e五行生克关系.被生://被生， 印授， 偏印
                    if (this.isYang == inTG.isYang)
                    {
                        ret =  ZYOEnum.e八字六神.偏印;
                    }
                    else
                    {
                        ret =  ZYOEnum.e八字六神.印授;
                    }
                    break;
                case ZYOEnum.e五行生克关系.被克://被克， 正官， 煞
                    if (this.isYang == inTG.isYang)
                    {
                        ret =  ZYOEnum.e八字六神.煞;
                    }
                    else
                    {
                        ret =  ZYOEnum.e八字六神.正官;
                    }
                    break;
                case ZYOEnum.e五行生克关系.生://生， 食神， 伤官
                    if (this.isYang == inTG.isYang)
                    {
                        ret =  ZYOEnum.e八字六神.食神;
                    }
                    else
                    {
                        ret =  ZYOEnum.e八字六神.伤官;
                    }
                    break;
                case ZYOEnum.e五行生克关系.克://克， 正财，偏财
                    if (this.isYang == inTG.isYang)
                    {
                        ret =  ZYOEnum.e八字六神.偏财;
                    }
                    else
                    {
                        ret =  ZYOEnum.e八字六神.正财;
                    }
                    break;
                case ZYOEnum.e五行生克关系.比和://相同， 比肩，劫财
                    if (this.isYang == inTG.isYang)
                    {
                        ret =  ZYOEnum.e八字六神.比肩;
                    }
                    else
                    {
                        ret =  ZYOEnum.e八字六神.劫财;
                    }
                    break;
            }
            return ret;
        }
    }

    /// <summary>
    /// Summary description for DiZhi.
    /// </summary>
    public class class地支 : ZYObject
    {

        public class天干[] 地蔵天干;

        internal override void preLoad()
        {
            this.Sum = 12;
            this.EnumType = typeof(e地支);
            base.preLoad();
        }

        internal override void postLoad()
        {
            base.postLoad();
            //
        }

        public class地支():base()
        {
        }

        public class地支(String strName)
            : base(strName)
        {
            this.五行属性 = (e五行)Enum.Parse(typeof(e五行), 资源.地支.五行.Split(';')[this.ID], true);
            this.Set地蔵天干();
        }
        public class地支(int iID)
            : base(iID)
        {
            this.五行属性 = (e五行)Enum.Parse(typeof(e五行), 资源.地支.五行.Split(';')[this.ID], true);

            this.Set地蔵天干();

        }
        public class地支(e地支 eDZ)
            : this((int)eDZ)
        {

        }

        private void Set地蔵天干()
        {
            String[] tgs = 资源.地支.地藏天干.Split(';')[this.ID].Split(',');

            int CountHiddenTG = tgs.GetLength(0);
            地蔵天干 = new class天干[CountHiddenTG];

            for (int i = 0; i < CountHiddenTG; i++)
            {
                地蔵天干[i] = new class天干(tgs[i]);
            }
        }

        public bool is三合(class地支 dz1, class地支 dz2)//三合
        {
            if (this.ID == dz1.ID || this.ID == dz2.ID || dz1.ID == dz2.ID) // the same DZ
                return false;
            int i, ii, iii;
            i = this.ID - dz1.ID;
            ii = this.ID - dz2.ID;
            iii = dz1.ID - dz2.ID;

            i = i % 4;
            ii = ii % 4;
            iii = iii % 4;

            if ((i == 0) & (ii == 0) & (iii == 0))
            {

                Trace.Write(this.Name + dz1.Name + dz2.Name + " 三合");
                return true;
            }
            else
            {
                Trace.Write(this.Name + dz1.Name + dz2.Name + " -----------");

                return false;
            }

        }

        public bool is合(class地支 dz) //合
        {
            int i = this.ID + dz.ID;
            i = i % 12;

            if (i == 3)
                return true;
            else
                return false;
        }


    }

    /// <summary>
    /// Summary description for JiaZi.
    /// </summary>
    public class class甲子 : ZYObject
    {
        private class天干 pTG;
        private class地支 pDZ;
        private class甲子 pHead;

        private ZYOEnum.e元 pYuan;

        public class天干 天干
        {
            get { return this.pTG; }

        }
        public class地支 地支
        {
            get { return this.pDZ; }
        }

        private class甲子 pXun;
        public class甲子 旬首
        {
            get { return this.pXun; }
        }
        public class甲子 上元符头 //甲子、己卯、甲午、己酉四上元之符头先到
        {
            get { return this.pHead; }
        }

        public ZYOEnum.e元 所属之元
        {
            get { return this.pYuan; }
        }

        public class地支[] DZ旬空 = new class地支[2];
        //public String 纳音;


        public static class甲子 operator +(class甲子 jz, int delta)
        {
            return new class甲子(jz.ID + delta);
        }



        public class甲子()
            : base()
        {

        }

        public class甲子(String strName)
            : base(strName)
        {

            this.pTG = new class天干(this.Name.Substring(0, 1));
            this.pDZ = new class地支(this.Name.Substring(1, 1));

        }

        public class甲子(int iID)
            : base(iID)
        {

            this.pTG = new class天干(this.Name.Substring(0, 1));
            this.pDZ = new class地支(this.Name.Substring(1, 1));

        }

        public class甲子(int 天干ID, int 地支ID)
            : this()
        {
            preLoad();
            pTG = new class天干(天干ID);
            pDZ = new class地支(地支ID);
            this.Name = 天干.Name.Trim() + 地支.Name.Trim();

            postLoad();

        }

        internal override void preLoad()
        {
            this.Sum = 60;
            this.EnumType = typeof(e甲子);
            base.preLoad();
        }

        internal override void postLoad()
        {
            base.postLoad();


            this.pXun = Rank(10); // 六甲旬首

            class甲子 Xun = this.pXun;

            //this.DZ旬空[0] = new class地支(Xun.地支.ID - 2);
            //this.DZ旬空[1] = new class地支(Xun.地支.ID - 1);

            this.pHead = Rank(15);//甲子、己卯、甲午、己酉四上元之符头
            int delta = this - this.pHead;

            switch (delta / 5)
            {
                case 0:
                    this.pYuan = ZYOEnum.e元.上元;
                    break;
                case 1:
                    this.pYuan = ZYOEnum.e元.中元;
                    break;
                case 2:
                    this.pYuan = ZYOEnum.e元.下元;
                    break;


            }
        }//postLoad


        private class甲子 Rank(int iDividby)
        {
            class甲子 retJZ = null;
            int iRank;

            if (ID % iDividby == 1) // this is the Rank
            {
                retJZ = this;
            }
            else
            {
                if (this.ID == 0) //癸亥 is 60ID
                {
                    iRank = (60 - 1) / iDividby;

                }
                else
                {
                    iRank = (this.ID - 1) / iDividby;
                }


                retJZ = new class甲子(iRank * iDividby + 1);

            }

            return retJZ;
        }
    }


    /// <summary>
    /// Summary description for JieQi.
    /// </summary>
    public class class节气 : ZYObject
    {
        //private const double OneYear = 365.2427806713;
        private DateTime JQTime;
        private int pYear;

        public DateTime 节气日期
        {
            get
            {
                return JQTime;
            }
        }
        private class甲子 jzDay;
        public class甲子 日甲子
        {
            get { return this.jzDay; }
        }

        private class甲子 pHead;
        public class甲子 节气上元符头
        {
            get { return this.pHead; }
        }

        public bool is闰;
        private class甲子 pHead2;
        public class甲子 闰节气上元符头
        {
            get { return this.pHead2; }
        }

        private DateTime JQBaseTime1996;

        private int[] JU;
        public int[] 局 // 上中下三元 之局
        {
            get { return this.JU; }
        }

         private int intLocation;

        public static class节气 operator + (class节气 jq, int delta)
        {
            int newJQID = jq.ID + delta;
            int newYear = jq.节气日期.Year;

            if (newJQID >= jq.Sum)
            {
                newYear += newJQID / jq.Sum;
            }
            if (newJQID < 0)
            {
                newYear += newJQID / jq.Sum - 1;
            }

            return new class节气(newJQID, newYear);
        }

        public static class节气 operator ++ (class节气 jq)
        {
            int newJQID = jq.ID + 1;
            int newYear = jq.节气日期.Year;

            if (newJQID == jq.Sum) //jq == 冬至 ID == 23
            {
                newJQID = 0;
                newYear++;
            }
            return new class节气(newJQID,newYear);
        }

        public static class节气 operator --(class节气 jq)
        {
            int newJQID = jq.ID - 1;
            int newYear = jq.节气日期.Year;

            if (newJQID == -1) //jq == 小寒 ID == 0
            {
                newJQID = 23;
                newYear--;
            }
            return new class节气(newJQID, newYear);
        }

        internal override void preLoad()
        {
            Sum = 24;
            this.EnumType = typeof(e节气);
            base.preLoad();
        }

        internal override void postLoad()
        {
            base.postLoad();
            //

        }


        public class节气():base(GetCurrentMonthJQID(DateTime.Today.Month))
        {
            iniJQ(DateTime.Today.Year);

        }

        public class节气(String strName, int iYear):base(strName)
        {
            iniJQ(iYear);

        }

        public class节气(int iID, int iYear):base(iID)
        {
            iniJQ(iYear);

        }
        public class节气(DateTime dt)
        {
            int Year = dt.Year;
            int Month = dt.Month;

            ID = GetCurrentMonthJQID(Month);

            iniJQ(Year);

        }


        private void iniJQ(int iYear)
        {
            JQBaseTime1996 = DateTime.Parse(GetResourceString(资源.节气.节气1996));
            String[] JuShu = GetResourceString(资源.节气.局数).Split(',');

            JU = new int[3];
            JU[0] = int.Parse(JuShu[0]);
            JU[1] = int.Parse(JuShu[1]);
            JU[2] = int.Parse(JuShu[2]);

            intLocation = int.Parse(GetResourceString(资源.节气.位置));

            JQTime = GetCurentMonthJQ(iYear);

            //计算 日 甲子===============================================================

            DateTime DT1997 = new DateTime(1997, 3, 22, 0, 0, 0, 0);// 1997,3,23是甲子日
            System.TimeSpan Duration = JQTime.Date - DT1997;

            int Dur = Duration.Days;

            while (Dur < 0)
                Dur = Dur + 60000;

            this.jzDay = new class甲子(Dur % 60);

            // 上元符头 =======
            is闰 = false;
            int delta = jzDay - jzDay.上元符头; //delta should less than 15

            this.pHead = null;
            this.pHead2 = null;

            if (delta <= 10)
            {
                this.pHead = jzDay.上元符头;
                if (this.Name == "大雪" || this.Name == "芒种")  //可能置闰
                {
                    if (delta == 10 || delta == 9) //置闰
                    {
                        is闰 = true;
                        this.pHead2 = jzDay.上元符头 + 15; // 下一个符头
                    }
                }
                else
                {
                // bug: 刚刚置闰后的冬至、夏至，会有delta == 9，10，应该取下一个符头
                   // "大雪" 22 "芒种" 10
                    class节气 jq大雪 = new class节气("大雪", this.JQTime.Year);
                    class节气 jq去年大雪 = new class节气("大雪", this.JQTime.Year - 1);
                    class节气 jq芒种 = new class节气("芒种", this.JQTime.Year);

                    if ((this - jq大雪 < 5) && jq大雪.is闰)
                    {
                        this.pHead = jzDay.上元符头 + 15; // 下一个符头
                    }

                    if ((this - jq去年大雪 < 5) && jq去年大雪.is闰)
                    {
                        this.pHead = jzDay.上元符头 + 15; // 下一个符头
                    }

                    if ((this - jq芒种 < 5) && jq芒种.is闰)
                    {
                        this.pHead = jzDay.上元符头 + 15; // 下一个符头
                    }


                }




            }
            else // next 符头
            {
                this.pHead = jzDay.上元符头 + 15; // 下一个符头
            }

        }

        private static int GetCurrentMonthJQID(int Month)
        {
            if (Month < 0 || Month > 12)
            {
                Trace.Write("Month - {0} is out of bound", Month.ToString());
                return -1;
            }

            int ret;

            ret = 2 * (Month - 1) % 24;

            return ret;
        }
        
        private DateTime GetCurentMonthJQ(int Year)
        {
            return (JQBaseTime1996.AddDays((Year - 1996) * Double.Parse(DefaultValues.太阳年常数)));
        }
    }

    /// <summary>
    /// Summary description for Gua8.
    /// </summary>
    public class class八卦 : ZYObject
    {
        public int 先天数;	// the Number that represent the GUA
        public String 方向;	//Direction

        public class地支 DownDZ;		//iDownID
        public class地支 UpDZ;			//iUpID

        internal override void preLoad()
        {
            Sum = 8;
            this.EnumType = typeof(e八卦ID);
            base.preLoad();
        }

        internal override void postLoad()
        {
            base.postLoad();
            //
            
            五行属性 = (e五行)(Enum.Parse(typeof(e五行),GetResourceString(资源.八卦.五行),true));
            先天数 = int.Parse(GetResourceString(资源.八卦.先天数));
            方向 = GetResourceString(资源.八卦.方位);
            int iDown = int.Parse(GetResourceString(资源.八卦.下卦地支ID));
            int iUP = int.Parse(GetResourceString(资源.八卦.上卦地支ID));
            int iYang = int.Parse(GetResourceString(资源.八卦.阴阳));

            DownDZ = new class地支(iDown);
            UpDZ = new class地支(iUP);


        }
        public class八卦():base()
        {
        }

        public class八卦(String strName)
            : base(strName)
        {
        }
        public class八卦(int iID)
            : base(iID)
        {
        }

    }

    /// <summary>
    /// Summary description for GUA64.
    /// </summary>
    public class class六十四卦 : ZYObject
    {
        public int Number;	//序号　num

        private int iShiID;
        private int iYingID;

        public class爻 世爻;
        public class爻 应爻;

        private int ChangeRecordID = 0;
        public int 变卦记录ID
        {
            get { return ChangeRecordID; }
            set
            {
                ChangeRecordID = value;

                this.初始化爻s(this.五行属性);
                this.卦宫64.初始化爻s(this.五行属性);

                if (0 != ChangeRecordID)
                {
                    变卦 = new class六十四卦(this.ID ^ ChangeRecordID); // Binary OR
                    变卦.初始化爻s(this.五行属性);
                }

                互卦 = new class六十四卦(((this.ID << 1) & 56) | ((this.ID >> 1) & 7));
            }
        }

        public class八卦 上卦8;	    //上卦
        public class八卦 下卦8;	    //下卦
        public class八卦 卦宫8;    //belong 卦宫
        public class六十四卦 卦宫64;
        public class六十四卦 变卦;
        public class六十四卦 互卦;

        public class爻[] 爻s;      //base from 0

        public String 卦象;        //卦象Meaning
        public String 彖曰;	        //彖曰 zhuan
        public String 象曰;	        //象曰 xiang


        internal override void preLoad()
        {
            Sum = 64;
            this.EnumType = typeof(e六十四卦ID);

            base.preLoad();
        }

        internal override void postLoad()
        {
            base.postLoad();

            iShiID = int.Parse(GetResourceString(资源.六十四卦.世));
            iYingID = mod((iShiID + 3), 6);


            int iUP = this.ID / 8;
            int iDown = this.ID % 8;
            int iBelong = int.Parse(GetResourceString(资源.六十四卦.卦宫));

            Number =(int)Enum.Parse(typeof(e六十四卦by数), this.Name,true);
            //卦象 = Row["Meaning"].ToString(); //卦象Meaning
            //彖曰 = Row["Zhuan"].ToString(); //彖曰 zhuan
            //象曰 = Row["Xiang"].ToString();//象曰 xiang

            上卦8 = new class八卦(iUP);
            下卦8 = new class八卦(iDown);
            卦宫8 = new class八卦(iBelong);

            五行属性 = 卦宫8.五行属性;

            if (this.ID == 卦宫8.ID * 9) // 本卦就是卦宫
            {
                this.卦宫64 = this;
            }
            else
            {
                //卦宫8.ID 为下卦ID; 卦宫8.ID*8 为上卦ID
                this.卦宫64 = new class六十四卦(卦宫8.ID * 9);
            }

            爻s = new class爻[6];

        }

        public class六十四卦():base()
        {
            变卦 = null;
            互卦 = null;
        }

        public class六十四卦(String strName)
            : base(strName)
        {
        }
        public class六十四卦(int iID)
            : base(iID)
        {
        }

        public void 初始化爻s(e五行 本卦的五行)
        {
            for (int i = 0; i < 6; i++)
            {
                爻s[i] = new class爻(i, this, 本卦的五行);
                爻s[i].is动 = (ChangeRecordID & (int)System.Math.Pow(2, i)) != 0; //Binary AND
            }

            this.世爻 = 爻s[iShiID - 1];
            this.应爻 = 爻s[iYingID - 1];

        }
    }

    /// <summary>
    /// Summary description for 爻.
    /// </summary>
    public class class爻: ZYObject
    {
        //ID--序号 start from 0
        //Name--六亲+地支+ 五行：父母子水
        
        public class地支 地支;
        public ZYOEnum.e六神 六神;

        public bool is动 = false;
        public String 爻辞; //爻辞

        public class爻 变爻;

        public class爻()
        {
            变爻 = null;
        }

        public class爻(int 序号0起, class六十四卦 本卦, e五行 本卦的五行)
            : this()
        {
            ID = 序号0起;

            isYang = ((本卦.ID >> ID) % 2) == 1 ? true : false;

            class地支 dz本卦初始地支;
            if (ID < 3)	//下卦
            {
                dz本卦初始地支 = 本卦.下卦8.DownDZ;
            }
            else //上卦
            {
                dz本卦初始地支 = 本卦.上卦8.DownDZ;
            }

            //下挂上卦的公式相同都用pDownDZ计算
            if (dz本卦初始地支.isYang)
            {
                //阳性地支
                地支 = new class地支(dz本卦初始地支.ID + ID * 2);
            }
            else
            {
                //阴性地支
                地支 = new class地支(dz本卦初始地支.ID - ID * 2 + dz本卦初始地支.Sum);
            }

            五行属性 = this.地支.五行属性;
            // Mapping 生克关系 = ZYOEnum.六神
            六神 = (ZYOEnum.e六神)ZYOEnum.Compair(五行属性, 本卦的五行);

            Name = 六神.ToString() + 地支.Name + 五行属性.ToString();

            DataTable dt易经爻辞 = DataFactory.ExecuteQuery(QueryStrings.Query易经爻辞, 本卦.ID.ToString(), (序号0起 + 1).ToString());
            爻辞 = dt易经爻辞.Rows[0]["YaoMeans"].ToString();

        }
    }
}
//最大公约数和最小公倍数
//void main()
//{
//    int m(int x,int y);
//    int a,b,t,p,q;
//    printf("请输入两个正整数:\n");
//    scanf("%d,%d",&p,&q);
//    if (p==q)
//    {
//        printf("最大公约数和最小公倍数均为:%d\n",p);
//    }
//    else if(p<q)
//    {
//        t=p;
//        p=q;
//        q=t;
//        a=m(p,q);      //调用一个函数
//        b=p*q/a    ;  //两个数的乘积等于它们最大公约数和最小公倍数的乘积
//        printf("最大公约数为:%d\n",a);
//        printf("最小公倍数为:%d\n",b);
//    }
//    else
//    {
//        a=m(p,q);     //同上
//        b=p*q/a;
//        printf("最大公约数为:%d\n",a);
//        printf("最小公倍数为:%d\n",b);
//    }
//}
////用辗转相除法求最大公约数
//# include<math.h>
// int m(int x,int y)
//{
//    int z;
//    while(y!=0)
//    {
//        z=x%y;
//        x=y;
//        y=z;
//    }
//    return(x)   ;
//}

//最大公约数 采用辗转相除法可以获得，
//最小公倍数 就是 x*y/最大公约数  了 ....


//用辗转相除法求两个数的最大公约数的步骤如下：
//先用小的一个数除大的一个数，得第一个余数；
//再用第一个余数除小的一个数，得第二个余数；
//又用第二个余数除第一个余数，得第三个余数；
//这样逐次用后一个数去除前一个余数，直到余数是0为止。那么，最后一个除数就是所求的最大公约数（如果最后的除数是1，那么原来的两个数是互质数）。

//例如求1515和600的最大公约数，

//第一次：用600除1515，商2余315；
//第二次：用315除600，商1余285；
//第三次：用285除315，商1余30；
//第四次：用30除285，商9余15；
//第五次：用15除30，商2余0。

//1515和600的最大公约数是15。

//辗转相除法是求两个数的最大公约数的方法。如果求几个数的最大公约数，可以先求两个数的最大公约数，再求这个最大公约数与第三个数的最大公约数。这样依次下去，直到最后一个数为止。最后所得的一个最大公约数，就是所求的几个数的最大公约数。
